<template>
  <div>
<!--    <uni-popup ref="registerPopup" type="center">-->
<!--      <div class="registerPopup">-->
<!--        <div class="registerPopup_title">账号注册</div>-->
<!--        <div class="inputItem">-->
<!--          <span class="inputItem_title">需求类型</span>-->
<!--          <div class="inputItem_inputWrapper">-->
<!--            <uni-data-checkbox v-model="requestTypeSelected" :localdata="requestType"></uni-data-checkbox>-->
<!--          </div>-->
<!--        </div>-->

<!--        <div class="inputItem">-->
<!--          <span class="inputItem_title">姓名</span>-->
<!--          <div class="inputItem_inputWrapper">-->
<!--            <uni-easyinput v-model="name" placeholder="请输入姓名" :inputBorder="false"></uni-easyinput>-->
<!--          </div>-->
<!--        </div>-->
<!--        <div class="inputItem">-->
<!--          <span class="inputItem_title">联系方式</span>-->
<!--          <div class="inputItem_inputWrapper">-->
<!--            <uni-easyinput v-model="phone" placeholder="请输入联系方式" :inputBorder="false"></uni-easyinput>-->
<!--          </div>-->
<!--        </div>-->
<!--        <div class="inputItem">-->
<!--          <span class="inputItem_title">验证码</span>-->
<!--          <div class="inputItem_inputWrapper">-->
<!--            <uni-easyinput v-model="smscode" placeholder="请输入验证码" :inputBorder="false"></uni-easyinput>-->
<!--          </div>-->
<!--          <span class="inputItem_smscode" @click="sendCode">获取验证码</span>-->
<!--        </div>-->
<!--        <div class="inputItem">-->
<!--          <span class="inputItem_title">电站名称</span>-->
<!--          <div class="inputItem_inputWrapper">-->
<!--            <uni-easyinput v-model="electronicName" placeholder="请输入电站名称" :inputBorder="false"></uni-easyinput>-->
<!--          </div>-->
<!--        </div>-->
<!--        <div class="inputItem">-->
<!--          <span class="inputItem_title">详细地址</span>-->
<!--          <div class="inputItem_inputWrapper" style="width: 250px">-->
<!--            <uni-combox v-model="city" :candidates="cities" placeholder="请选择所在城市" :border="false"></uni-combox>-->
<!--          </div>-->
<!--        </div>-->
<!--        <div class="inputItem">-->
<!--          <span class="inputItem_title">详细地址</span>-->
<!--          <div class="inputItem_inputWrapper">-->
<!--            <uni-easyinput v-model="address" placeholder="请输入详细地址" :inputBorder="false"></uni-easyinput>-->
<!--          </div>-->
<!--        </div>-->
<!--        <div class="registerPopup_register" @click="register">注册</div>-->
<!--        <div class="registerPopup_gotoLogin">已有账号，去<span @click="gotoLogin" style="color: #dd524d">登录</span></div>-->
<!--      </div>-->

<!--    </uni-popup>-->
    <button type="default" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">获取手机号</button>
  </div>
</template>

<script>
  import Http from '@/libs/Http';
  import wxPromisify from "@/libs/wxPromisify";

  export default {
    components: {},
    data() {
      return {
        requestType: [
          {"value": '电站出售', "text": "电站出售"},
          {"value": '电站求购', "text": "电站求购"}
        ],
        cities: [
          '北京',
          '上海',
          '郑州',
          '深圳'
        ],
        requestTypeSelected: '电站出售',
        name: '',
        phone: '',
        electronicName: '',
        city: '',
        address: '',
        smscode: '',
      }
    },
    onLoad() {
      this.login();
      // this.$refs.registerPopup.open();
    },
    methods: {
      async sendCode() {
        let response = await Http.post('https://quanying.minhaoinfo.com/s/quanying-service-provider-portal/register/RegisterController/sendSmsCode.action',
          {
            mobile: this.phone
          })
        console.log(response.code);
      },
      async login() {
        try {
          let loginRes = await wxPromisify.login();
          console.log('loginRes',loginRes);
          let code = loginRes.code;
          if (code) {
            //发起网络请求
            let code2Session = await Http.get('https://www.zhangyifansjdd.top/api/wx/code2Session', {code})
            console.log('code2Session', code2Session);
            let userInfo =await wxPromisify.getUserInfo();
            console.log('userInfo',userInfo);
          }
        } catch (e) {
          console.log(e);
        }
      },
      async decryptPhoneNumber(res){
        console.log(res);
        let code = res.detail.code;
        let getAccessToken  = await Http.get('http://localhost:8080/api/wx/getAccessToken');
        console.log(getAccessToken.access_token);
        let getPhoneNumber  = await Http.post('http://localhost:8080/api/wx/getPhoneNumber',{
          code,
          access_token:getAccessToken.access_token
        });
        console.log(getPhoneNumber);
      },
      register() {
        console.log('register',
          this.requestTypeSelected,
          this.name,
          this.phone,
          this.electronicName,
          this.city,
          this.address,
          this.smscode,
        );
      },
      gotoLogin() {
        console.log('gotoLogin');
      }
    }
  }
</script>

<style>
  .registerPopup {
    font-size: 0;
    min-width: 300px;
    min-height: 100px;
    background: white;
    border-radius: 10px;
    padding: 15px;
  }

  .registerPopup_title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
  }

  .inputItem {
    border: 1px solid grey;
    border-radius: 10px;
    margin-bottom: 10px;
  }

  .inputItem_title {
    font-size: 14px;
    font-weight: 400;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 80px;
    border-right: 1px solid grey;
    margin-top: 5px;
    margin-bottom: 5px;
    margin-right: 5px;
  }

  .inputItem_inputWrapper {
    display: inline-block;
  }

  .inputItem_smscode {
    font-size: 12px;
    font-weight: 400;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: red;
    border-radius: 5px;
    color: white;
    padding: 2px 5px;
    margin-right: 10px;
  }

  .registerPopup_register {
    font-size: 16px;
    font-weight: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    background: red;
    border-radius: 10px;
    color: white;
    padding: 2px 5px;
    height: 30px;
    margin-bottom: 10px;
  }

  .registerPopup_gotoLogin {
    font-size: 12px;
    text-align: center;
    color: #555555;
  }
</style>
